package com.yiyang.domain;

import com.yiyang.constant.ResultCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("全局响应格式")
public class Result<T>  implements Serializable {
    @ApiModelProperty("状态码")
    private Integer code;
    @ApiModelProperty("数据")
    private T data;
    @ApiModelProperty("错误信息")
    private String msg;

    public static <T> Result<T>  success(){
        return new Result<T>(ResultCode.SUCCESS_CODE,null,"success");
    }

    public static <T> Result<T>  success(T data){
        return new Result<T>(ResultCode.SUCCESS_CODE,data,null);
    }

    public static  Result  fail(Integer code,String msg){
        return new Result(code,null,msg);
    }

}
